<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* CRM in Dashboard */
class Crm extends Controller {
	
	function Crm(){
		if(!$this->session->userdata('user_id')){
			redirect($this->config->item('auth'));
		}
        $this->load->model('dashboards');
		ini_set ('display_errors', 1);
		error_reporting(E_ERROR | E_WARNING | E_PARSE);
	}
	
	function index() {
		$month=date('m');
		
		if(($month=='01')|| ($month=='02') || ($month=='03')):
			$month1='01';
			$month1_name='Jan';
			$month2='02';
			$month2_name='Feb';
			$month3='03';
			$month3_name='Mar';
		elseif(($month=='04')|| ($month=='05') || ($month=='06')):	
			$month1='04';
			$month1_name='Apr';
			$month2='05';
			$month2_name='May';
			$month3='06';
			$month3_name='Jun';
		elseif(($month=='07')|| ($month=='08') || ($month=='09')):
			$month1='07';
			$month1_name='Jul';
			$month2='08';
			$month2_name='Aug';
			$month3='09';
			$month3_name='Sept';
		elseif(($month=='10')|| ($month=='11') || ($month=='12')):
			$month1='10';
			$month1_name='Okt';
			$month2='11';
			$month2_name='Nov';
			$month3='12';
			$month3_name='Dec';	
		endif;	
		
		$data = array(
                        'title'		=>	$this->lang->line('dashboard'),
                        'table'     =>  array(
                                                'customers'                 =>  $this->dashboards->getContact(5),
												'clients' 	        		=>  $this->dashboards->getCustomers(7,$this->config->item('prospect')),
												'client_inhouse' 	        =>  $this->dashboards->getCustomers(7,$this->config->item('prospect'),'IN HOUSE'),
												'client_dna' 	        	=>  $this->dashboards->getCustomers(7,$this->config->item('prospect'),'DNA'),
												'clientx' 	                =>  $this->dashboards->getCustomers(7,$this->config->item('existing')),
                                                'users'                     =>  $this->dashboards->getUsers(),
												'allUsers'                  =>  $this->dashboards->getAllUsers(),
                                                'type'                      =>  $this->dashboards->getType(),
                                                'activity_transaction'      =>  $this->dashboards->getAllThisTransaction(date('W')+1),
                                                'jo'                        =>  $this->dashboards->getJOMonth(),
                                                'se'                        =>  $this->dashboards->getUserID($this->config->item('se'),$this->session->userdata('user_group')),
                                                'activityperiode'           =>  $this->dashboards->getActivityPerPeriode(),
                                                'activityperiodeM'          =>  $this->dashboards->getActivityPerPeriode('Month'),
                                                'activityMonth0103'         =>  $this->dashboards->activity3Month('01','03'),
                                                'activityMonth0406'         =>  $this->dashboards->activity3Month('04','06'),
                                                'activityMonth0709'         =>  $this->dashboards->activity3Month('07','09'),
                                                'activityMonth1012'         =>  $this->dashboards->activity3Month('10','12'),
                                                'totalJO'                   =>  $this->dashboards->getJOTotal()
                                             ),   
						'content'	=> 	'dashboard',
						'month'		=>	array(
												'id1'					=>	$month1,
												'name1'					=>	$month1_name,
												'id2'					=>	$month2,
												'name2'					=>	$month2_name,
												'id3'					=>	$month3,
												'name3'					=>	$month3_name,
											 ),
                        'grid'      =>  array(
                                                'grid1'             =>  $this->lang->line('latest_contact'),
                                                'grid2'             =>  $this->lang->line('graph_report'),
                                                'grid3'             =>  $this->lang->line('not_activity'),
                                                'grid4'             =>  $this->lang->line('jo_report'),
                                             ),  
						'menu' 		=> 	array(
												'dashboard_active'	=>	$this->config->item('active'),
												'contact_active'	=>	$this->config->item('empty'),
                                                'contactdna_active'	=>	$this->config->item('empty'),
												'activity_active'	=>	$this->config->item('empty'),
												'job_active'		=>	$this->config->item('empty'),
												'user_active'		=>	$this->config->item('empty'),
												'call_active'		=>	$this->config->item('empty'),
												'report_active'		=>	$this->config->item('empty'),
												'master_active'		=>	$this->config->item('empty'),
												'graphic_active'	=>	$this->config->item('empty'),
												'setting_active'	=>	$this->config->item('empty'),
											 ),
						'tab'		=>	array(
												'tab1'				=>	$this->lang->line('list'),
                                                'tab1_link'			=>	$this->config->item('userlist'),
												'tab1_active'		=>	$this->config->item('active'),
												'tab2'				=>	'',
                                                'tab2_link'			=>	$this->config->item('useradd'),
												'tab2_active'		=>	$this->config->item('empty'),
												'tab3'				=>	'',
												'tab4'				=>	'',
												'tab5'				=>	'',
												'tab6'				=>	'',
												'tab7'				=>	'',
												'tab8'				=>	''
											 )		
					 );
		$this->load->vars($data);
		$this->load->theme('default');
	}
	
	function updateProspect($id='',$div=''){
		//if($id):
				if($this->session->userdata('user_pos')==$this->config->item('se')):
					$this->dashboards->getUpdateProspectTA($id);
				elseif ($this->session->userdata('user_pos')==$this->config->item('spv')):
					$this->dashboards->getUpdateProspectSE($id);
				endif;		
                $this->session->set_flashdata('messagex','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
                redirect($this->input->server('HTTP_REFERER')); 
        //else:
			//$this->session->set_flashdata('messagex','<span class="message error"><strong>Error</strong>message - no Choose Customer </span>');
               // redirect($this->input->server('HTTP_REFERER')); 
		//endif;
	}
	
	function updateAll($div){
		if($this->session->userdata('user_pos')==$this->config->item('se')):
				//$this->dashboards->getUpdateProspectTA($id);
		elseif ($this->session->userdata('user_pos')==$this->config->item('spv')):
				$this->dashboards->getUpdateAll($div);
		endif;		
        $this->session->set_flashdata('messagex','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
        redirect($this->input->server('HTTP_REFERER')); 
	}
	
	function updateReject($id,$div=''){
		//if($id):
				if($this->session->userdata('user_pos')==$this->config->item('se')):
					$this->dashboards->getDeleteCustomer($id);
				elseif ($this->session->userdata('user_pos')==$this->config->item('spv')):
					$this->dashboards->getProspectUser($id,$div);
				endif;		
                $this->session->set_flashdata('messagex','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
                redirect($this->input->server('HTTP_REFERER')); 
        //else:
		//	$this->session->set_flashdata('messagex','<span class="message error"><strong>Error</strong>message - no Choose Customer </span>');
        //        redirect($this->input->server('HTTP_REFERER')); 
		//endif;
	}
	
	function updateExisting($id){
		if($id):
				if ($this->session->userdata('user_pos')==$this->config->item('spv')):
					$this->dashboards->getUpdateExisting($id);
				endif;		
                $this->session->set_flashdata('messagex','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
                redirect($this->input->server('HTTP_REFERER')); 
        else:
			$this->session->set_flashdata('messagex','<span class="message error"><strong>Error</strong>message - no Choose Customer </span>');
                redirect($this->input->server('HTTP_REFERER')); 
		endif;
	}
	
	function updateExistingReject($id){
		if($id):
				if($this->session->userdata('user_pos')==$this->config->item('spv')):
					//$this->dashboards->getDeleteCustomer($id);
					$this->dashboards->getRejectSpv($id);
				endif;		
                $this->session->set_flashdata('messagex','<span class="message success"><strong>Success</strong>message - '.$this->lang->line('m_update').'  </span>');
                redirect($this->input->server('HTTP_REFERER')); 
        else:
			$this->session->set_flashdata('messagex','<span class="message error"><strong>Error</strong>message - no Choose Customer </span>');
                redirect($this->input->server('HTTP_REFERER')); 
		endif;
	}
    
    function periode(){
        if($this->input->post('periode')=='day')
            $this->session->set_userdata('periode','');
        elseif ($this->input->post('periode')=='month')
            $this->session->set_userdata('periode','month');
        elseif ($this->input->post('periode')=='3month')
            $this->session->set_userdata('periode','3month');    
        redirect($this->input->server('HTTP_REFERER'));        
    }
	 
	function performance(){
		if($this->session->userdata('user_group')==$this->config->item('ta')):
		
			if($this->input->post('periode')=='week'):
				$this->session->set_userdata('performance','');
			elseif ($this->input->post('periode')=='month'):
				$this->session->set_userdata('performance','month');
			elseif ($this->input->post('periode')=='3month'):
				$this->session->set_userdata('performance','3month'); 
			endif;
		else:
			for($x=1;$x<=10;$x++):
				if($this->input->post('periode'.$x)=='week'):
					$this->session->set_userdata('performance'.$x,'');
				elseif ($this->input->post('periode'.$x)=='month'):
					$this->session->set_userdata('performance'.$x,'month');
				elseif ($this->input->post('periode'.$x)=='3month'):
					$this->session->set_userdata('performance'.$x,'3month');
				elseif($this->input->post('user')):
					$this->session->set_userdata('user',$this->input->post('user'));
				endif;
			endfor;	
		endif;
        redirect($this->input->server('HTTP_REFERER'));    
		
    }
	
	
	
	public function exportse($periode=''){
		if($periode==''){
			$this->excellday();
		}
		elseif($periode=='month'){
			$this->excellmonth();
		} 
		elseif($periode='3month'){
			$this->excell3month();
		}
	}
	
	public function excellday(){
		$data['table']		= array(
									'activityperiode'           =>  $this->dashboards->getActivityPerPeriode()
								);
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("Monitoring SE Per Day")
					->setDescription("description");
					 $objPHPExcel->setActiveSheetIndex(0);
		$styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
                        'type'       => Style_Fill::FILL_SOLID,
                        'rotation'   => 0,
                        'startcolor' => array(
                                'rgb' => 'CCCCCC'
                        ),
                        'endcolor'   => array(
                                'argb' => 'CCCCCC'
                        )
                );       
	  	
		$fontArray = array(
			'font' => array(
			'bold' => true
			)
			);
		
		$row=1;
        $col=0;
		
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Date');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'SE Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		//Call
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Call');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		//Meeting
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Meeting');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		//FU
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'FU');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
		
		//Invalid Data
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Invalid Data');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
		
		//Total
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Total');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
		
		//Total
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'PE');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
		
		$row=$row+1;
		
		foreach($data['table']['activityperiode'] as $rec):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['activity_date']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['pic']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$c=$rec['calls']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$m=$rec['meeting']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$f=$rec['fu']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$i=$rec['invalid']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$c+$m+$f+$i);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			if($rec['fu']==0):
				$pe = 0	;
			else:
				$pe = (($rec['meeting']/$rec['fu']+$rec['meeting']))*100;
			endif;
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$pe);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			
			$row++;
		endforeach;
		// Save it as an excel 2003 file
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
        $file="SE_Monitoring.xls";
        $objWriter->save('crm-assets/'.$file);
        redirect('crm-assets/'.$file,301);
	}
	
	
	public function excellmonth(){
		$data['table']		= array(
									'activityperiode'           =>  $this->dashboards->getActivityPerPeriode('Month')
								);
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("Monitoring SE Per Day")
					->setDescription("description");
					 $objPHPExcel->setActiveSheetIndex(0);
		$styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
                        'type'       => Style_Fill::FILL_SOLID,
                        'rotation'   => 0,
                        'startcolor' => array(
                                'rgb' => 'CCCCCC'
                        ),
                        'endcolor'   => array(
                                'argb' => 'CCCCCC'
                        )
                );       
	  	
		$fontArray = array(
			'font' => array(
			'bold' => true
			)
			);
		
		$row=1;
        $col=0;
		
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Month');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'SE Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		//Call
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Call');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		//Meeting
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Meeting');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		//FU
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'FU');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
		
		//Invalid Data
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Invalid Data');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
		
		//Total
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Total');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
		
		//Total
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'PE');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
		
		$row=$row+1;
		
		foreach($data['table']['activityperiode'] as $rec):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['monthly']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['pic']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$c=$rec['calls']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$m=$rec['meeting']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$f=$rec['fu']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$i=$rec['invalid']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$c+$m+$f+$i);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			if($rec['fu']==0):
				$pe = 0	;
			else:
				$pe = (($rec['meeting']/$rec['fu']+$rec['meeting']))*100;
			endif;
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$pe);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			
			$row++;
		endforeach;
		// Save it as an excel 2003 file
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
        $file="SE_Monitoring_Per_Month.xls";
        $objWriter->save('crm-assets/'.$file);
        redirect('crm-assets/'.$file,301);
	}
										
	public function excell3month(){
		$data['table']		= array(
												'se'                        =>  $this->dashboards->getUserID($this->config->item('se'),$this->session->userdata('user_group'))
								);
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("Monitoring SE Per Day")
					->setDescription("description");
					 $objPHPExcel->setActiveSheetIndex(0);
		$styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
                        'type'       => Style_Fill::FILL_SOLID,
                        'rotation'   => 0,
                        'startcolor' => array(
                                'rgb' => 'CCCCCC'
                        ),
                        'endcolor'   => array(
                                'argb' => 'CCCCCC'
                        )
                );       
	  	
		$fontArray = array(
			'font' => array(
			'bold' => true
			)
			);
		
		$row=1;
        $col=0;
		
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Periode');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'SE Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		//Call
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Call');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		//Meeting
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Meeting');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		//FU
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'FU');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
		
		//Invalid Data
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Invalid Data');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(20);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
		
		//Total
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Total');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
		
		//Total
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'PE');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
		
		$row=$row+1;
		foreach($data['table']['se'] as $rec):
			$val=$this->dashboards->activity3Month('01','03',$rec['username']);
			if($val):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Jan - Mar');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['username']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
				
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$c=$val['calls']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$m=$val['meeting']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$f=$val['fu']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$i=$val['invalid']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$c+$m+$f+$i);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
				
				if($val['fu']==0):
					$pe = 0	;
				else:
					$pe = (($val['meeting']/$val['fu']+$val['meeting']))*100;
				endif;
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$pe);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
				
				$row++;
			endif;	
		endforeach;
		
		$row++;
		foreach($data['table']['se'] as $rec):
			$val=$this->dashboards->activity3Month('04','06',$rec['username']);
			
			if($val):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'April - Juni');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['username']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
				
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$c=$val['calls']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$m=$val['meeting']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$f=$val['fu']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$i=$val['invalid']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$c+$m+$f+$i);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
				
				if($val['fu']==0):
					$pe = 0	;
				else:
					$pe = (($val['meeting']/$val['fu']+$val['meeting']))*100;
				endif;
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$pe);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
				
				$row++;
			endif;	
		endforeach;
		
		$row++;
		foreach($data['table']['se'] as $rec):
			$val=$this->dashboards->activity3Month('07','09',$rec['username']);
			
			if($val):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Juli - September');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['username']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
				
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$c=$val['calls']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$m=$val['meeting']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$f=$val['fu']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$i=$val['invalid']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$c+$m+$f+$i);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
				
				if($val['fu']==0):
					$pe = 0	;
				else:
					$pe = (($val['meeting']/$val['fu']+$val['meeting']))*100;
				endif;
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$pe);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
				
				$row++;
			endif;	
		endforeach;
		
		$row++;
		foreach($data['table']['se'] as $rec):
			$val=$this->dashboards->activity3Month('10','12',$rec['username']);
			
			if($val):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Oktober - Desember');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['username']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
				
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$c=$val['calls']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$m=$val['meeting']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$f=$val['fu']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$i=$val['invalid']);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$c+$m+$f+$i);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
				
				if($val['fu']==0):
					$pe = 0	;
				else:
					$pe = (($val['meeting']/$val['fu']+$val['meeting']))*100;
				endif;
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$pe);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
				
				$row++;
			endif;	
		endforeach;
		
		
		// Save it as an excel 2003 file
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
        $file="SE_Monitoring_Per_3_Month.xls";
        $objWriter->save('crm-assets/'.$file);
        redirect('crm-assets/'.$file,301);
	}
	
	public function exportweekly($user,$week){
		$data['table']		= array(
									'activity'           =>  $this->dashboards->getWeekActivity($user,$week),
									'activity2'          =>  $this->dashboards->getWeekActivity($user,$week+1),
									'sales'				 =>	 $this->dashboards->getWeekSalesFail($user,$week),
									'jo'				 =>	 $this->dashboards->getWeekJob($user,$week)
								);
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("Weekly Report")
					->setDescription("description");
					 $objPHPExcel->setActiveSheetIndex(0);
		$styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
                        'type'       => Style_Fill::FILL_SOLID,
                        'rotation'   => 0,
                        'startcolor' => array(
                                'rgb' => 'CCCCCC'
                        ),
                        'endcolor'   => array(
                                'argb' => 'CCCCCC'
                        )
                );       
	  	
		$fontArray = array(
			'font' => array(
			'bold' => true
			)
			);
		
		$row=1;
		$col=0;
		
		//Title
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'This Week');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
       
		
		//Title
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Next Week');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
		
		$row=$row+1;
        $col=0;
		
		
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Date');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Time');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		//Customer Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Customer Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Pic');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Date');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Time');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
		
		//Customer Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'Customer Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'Pic');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+8)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getFill()->applyFromArray($fill);
		
		
		$row=$row+1;
		$x1=1;
		foreach($data['table']['activity'] as $rec):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['activity_date']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['activity_time']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$rec['customer_name']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$rec['pic']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
			
			$row++;
			$x1++;
		endforeach;
		
		$row=$row-($x1-1);
		$x2=1;
		foreach($data['table']['activity2'] as $rec):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$rec['activity_date']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$rec['activity_time']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$rec['customer_name']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$rec['pic']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
			
			$row++;
			$x2++;
		endforeach;
		
		if($x1>$x2){
			$row=$row+$x1;
		} elseif($x1==$x2){
			$row=$x1;
		} elseif($x1<$x2){
			$row=$x2+1;
		}
		
		$row+2;
		$col=0;
		//Title
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Sales Fail');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
       
	    $row++;
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Date in');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Date Out');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		//Customer Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Customer Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Type');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'Product Name');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(25);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Note');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(35);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
		
		$row++;
		$col=0;
		foreach($data['table']['sales'] as $rec):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['date_in']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['date_out']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$rec['customer_name']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$rec['type']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$rec['product_name']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$rec['note']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			$row++;
			$x2++;
		endforeach;
		
		$row=$row+2;
		$col=0;
		
		//Note
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Note');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		
		$row=$row+1;
		//Test
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Testing Note');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
       //$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		
		$row=$row+2;
		$col=0;
		//Title
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'New Deal');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
       
	    $row++;
		//Date
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Job No');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		//Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Date');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		//Customer Name
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Product');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(30);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Value');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(10);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'Bacth');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(25);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
		
		//Pic User
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Pic');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
		
		$row++;
		$col=0;
		foreach($data['table']['jo'] as $rec):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,$rec['no']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$rec['date_posting']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$rec['product_name']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$rec['invest']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$rec['batch']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$rec['pic']);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			$row++;
		endforeach;
		
		// Save it as an excel 2003 file
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
        $file="User_Week_".$user.'_'.$week.".xls";
        $objWriter->save('crm-assets/'.$file);
        redirect('crm-assets/'.$file,301);
	}
	
	function exportperformance($user='',$periode=''){
		
		if(($periode=='month') || ($periode=='3month') ):
			$month=date('m');
			if(($month=='01')|| ($month=='02') || ($month=='03')):
				$month1='01';
				$month1_name='Jan';
				$month2='02';
				$month2_name='Feb';
				$month3='03';
				$month3_name='Mar';
			elseif(($month=='04')|| ($month=='05') || ($month=='06')):	
				$month1='04';
				$month1_name='Apr';
				$month2='05';
				$month2_name='May';
				$month3='06';
				$month3_name='Jun';
			elseif(($month=='07')|| ($month=='08') || ($month=='09')):
				$month1='07';
				$month1_name='Jul';
				$month2='08';
				$month2_name='Aug';
				$month3='09';
				$month3_name='Sept';
			elseif(($month=='10')|| ($month=='11') || ($month=='12')):
				$month1='10';
				$month1_name='Okt';
				$month2='11';
				$month2_name='Nov';
				$month3='12';
				$month3_name='Dec';	
			endif;	
		endif;
		
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getProperties()->setTitle("Performance Report")
					->setDescription("description");
					 $objPHPExcel->setActiveSheetIndex(0);
		$styleArray = array( 'borders' => array( 'allborders' => array(
                             'style' => Style_Border::BORDER_THIN )));
        $fill = array(
                        'type'       => Style_Fill::FILL_SOLID,
                        'rotation'   => 0,
                        'startcolor' => array(
                                'rgb' => 'CCCCCC'
                        ),
                        'endcolor'   => array(
                                'argb' => 'CCCCCC'
                        )
                );       
	  	
		$fontArray = array(
			'font' => array(
			'bold' => true
			)
			);
		
		$row=1;
        $col=0;
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Status');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
		
		if(!$periode)
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Week I');
		elseif($periode=='month')
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$month1_name);
		elseif($periode=='3month')
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$month1_name);
		
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+1)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+2)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'');
        $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+3)->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+1,$row,$col+3,$row);
		
		
		if($periode != 'month'):
			if(!$periode)
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'Week II');
			elseif($periode=='month')
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$month2_name);
			elseif($periode=='3month')
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$month2_name);
			
			
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+4)->setWidth(15);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'');
			$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+5)->setWidth(15);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+4,$row,$col+5,$row);
			
			if(!$periode)
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Week III');
			elseif($periode=='month')
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$month3_name);
			elseif($periode=='3month')
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$month3_name);
			
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+6)->setWidth(15);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'');
			$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+7)->setWidth(15);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+6,$row,$col+7,$row);
			
			if(!$periode):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'Week IV');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+8)->setWidth(15);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getFill()->applyFromArray($fill);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,'');
				$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col+9)->setWidth(15);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getFill()->applyFromArray($fill);
				$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+8,$row,$col+9,$row);
			endif;
		endif;
		
		//batas
		$row++;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getFill()->applyFromArray($fill);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Data');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getFill()->applyFromArray($fill);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getFill()->applyFromArray($fill);
		$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+1,$row,$col+2,$row);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'Result');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getFill()->applyFromArray($fill);
		
		
		if($periode != 'month'):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'Data');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getFill()->applyFromArray($fill);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'Result');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getFill()->applyFromArray($fill);
			
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'Data');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getFill()->applyFromArray($fill);
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'Result');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getFill()->applyFromArray($fill);
			
			
			if(!$periode):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'Data');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getFill()->applyFromArray($fill);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,'Result');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getFill()->applyFromArray($fill);
			endif;
		endif;
		
		//batas
		$row++;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'New Client');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Effor TA');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		
		/* Data  Month 1/ Week I*/
		//WEEK ke 1
		if($this->session->userdata('user_group')==$this->config->item('user'))
			$this->db->where('rev',$user);
		elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
			$this->db->where('rev3',$user);		
			
		//Mandiri				
		$this->db->where('customer_from','Mandiri');
		$this->db->where('status_id',$this->config->item('prospect'));
		
		if(!$periode)
			$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',1);	
		elseif(($periode=='month') || ($periode=='3month') )
			$this->db->where('MONTH(date_stamp)',$month1);	
		
		$Q=$this->db->get('customers');
		$data=$Q->num_rows();
		/* Data  Month 1/ Week I */
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$data);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
		
		/* Result Week I / Month I */
		$this->db->where('pic',$user);
		$this->db->where('order_type','First Order');
		if(!$periode)
			$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',1);		
		elseif(($periode=='month')||($periode=='3month'))
			$this->db->where('MONTH(date_stamp)',$month1);
			
		$Q=$this->db->get('jobs');
		$data=$Q->num_rows();
		/* Result Week I / Month I */
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$data);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+3,$row,$col+3,$row+1);
        
		
		if($periode != 'month'):	
			/* Data  Month 2/ Week 2*/
			//WEEK ke 2
			if($this->session->userdata('user_group')==$this->config->item('user'))
				$this->db->where('rev',$user);
			elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
				$this->db->where('rev3',$user);		
				
				//Mandiri				
			$this->db->where('customer_from','Mandiri');
			$this->db->where('status_id',$this->config->item('prospect'));
			
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',2);	
			elseif($periode=='3month')
				$this->db->where('MONTH(date_stamp)',$month2);	
				
			$Q=$this->db->get('customers');
			$data=$Q->num_rows();
			/* Data  Month 1/ Week I */
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
		   
			/* Result Week 2 / Month 2 */
			$this->db->where('pic',$user);
			$this->db->where('order_type','First Order');
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',2);		
			elseif($periode=='3month')
				$this->db->where('MONTH(date_stamp)',$month2);
				
			$Q=$this->db->get('jobs');
			$data=$Q->num_rows();
			/* Result Week 2 / Month 2 */
		
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+5,$row,$col+5,$row+1);
			
			/* Data  Month 3/ Week 3 */
			//WEEK ke 3
			if($this->session->userdata('user_group')==$this->config->item('user'))
				$this->db->where('rev',$user);
			elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
				$this->db->where('rev3',$user);		
				
			//Mandiri				
			$this->db->where('customer_from','Mandiri');
			$this->db->where('status_id',$this->config->item('prospect'));
			
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',3);	
			elseif($periode=='3month')
				$this->db->where('MONTH(date_stamp)',$month3);
				
			$Q=$this->db->get('customers');
			$data=$Q->num_rows();
			/* Data  Month 3/ Week 3 */
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			/* Result Week 3 / Month 3 */
			$this->db->where('pic',$user);
			$this->db->where('order_type','First Order');
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',3);		
			elseif($periode=='3month')
				$this->db->where('MONTH(date_stamp)',$month3);
				
			$Q=$this->db->get('jobs');
			$data=$Q->num_rows();
			/* Result Week 3 / Month 3 */
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+7,$row,$col+7,$row+1);
			
			if(!$periode):
				/* Data  Week 4 */
				//WEEK ke 4
				if($this->session->userdata('user_group')==$this->config->item('user'))
					$this->db->where('rev',$user);
				elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
					$this->db->where('rev3',$user);		
					
				//Mandiri				
				$this->db->where('customer_from','Mandiri');
				$this->db->where('status_id',$this->config->item('prospect'));
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',4);
				$Q=$this->db->get('customers');
				$data=$Q->num_rows();
				/* Data  Month 4/ Week 4 */			
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$data);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				
				/* Result Week 4  */
				$this->db->where('pic',$user);
				$this->db->where('order_type','First Order');
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',4);			
				$Q=$this->db->get('jobs');
				$data=$Q->num_rows();
				/* Result Week 4 */
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,$data);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+9,$row,$col+9,$row+1);
			endif;
		endif;
		
		//batas
		$row++;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
				
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'Manajemen');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		
		/* Data  Week 1/Month1 */
		//WEEK/Month ke 1
		if($this->session->userdata('user_group')==$this->config->item('user'))
			$this->db->where('rev',$user);
		elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
			$this->db->where('rev3',$user);		
					
		//Manajemen				
		$this->db->where('customer_from','Manajemen');
		$this->db->where('status_id',$this->config->item('prospect'));
		if(!$periode)
			$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',1);	
		elseif(($periode=='month') || ($periode=='3month') )
			$this->db->where('MONTH(date_stamp)',$month1);	
			
		$Q=$this->db->get('customers');
		$data=$Q->num_rows();
		/* Data  Month 1/ Week 1 */
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,$data);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
       
		
		if($periode != 'month'):
			
			/* Data  Week 2 / Month 2 */
			//WEEK ke 2
			if($this->session->userdata('user_group')==$this->config->item('user'))
				$this->db->where('rev',$user);
			elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
				$this->db->where('rev3',$user);		
						
			//Manajemen	
			$this->db->where('customer_from','Manajemen');
			$this->db->where('status_id',$this->config->item('prospect'));
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',2);	
			elseif(($periode=='month') || ($periode=='3month') )
				$this->db->where('MONTH(date_stamp)',$month2);	
				
			$Q=$this->db->get('customers');
			$data=$Q->num_rows();
			/* Data  Month 2/ Week 2 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
		   
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			/* Data  Week 3 / Month 3 */
			//WEEK ke 3
			if($this->session->userdata('user_group')==$this->config->item('user'))
				$this->db->where('rev',$user);
			elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
				$this->db->where('rev3',$user);		
						
			//Manajemen		
			$this->db->where('customer_from','Manajemen');
			$this->db->where('status_id',$this->config->item('prospect'));
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',3);	
			elseif(($periode=='month') || ($periode=='3month') )
				$this->db->where('MONTH(date_stamp)',$month3);	
				
			$Q=$this->db->get('customers');
			$data=$Q->num_rows();
			/* Data  Month 3/ Week 3 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			
			if(!$periode):
				/* Data  Week 4 */
				//WEEK ke 4
				if($this->session->userdata('user_group')==$this->config->item('user'))
					$this->db->where('rev',$user);
				elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
					$this->db->where('rev3',$user);		
							
				//Manajemen				
				$this->db->where('customer_from','Manajemen');
				$this->db->where('status_id',$this->config->item('prospect'));
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',4);
				$Q=$this->db->get('customers');
				$data=$Q->num_rows();
				/* Data  Week 4 */
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$data);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,'');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
			endif;
		endif;
		
		//batas
		$row++;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,'');
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
       
		
		if($periode != 'month'):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
		   
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			
			if(!$periode):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,'');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
			endif;
		endif;
		
		//batas
		$row++;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'Existing Client');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
		
		/* Data  Week 1 / Month 1 */
		//WEEK ke 1
		if($this->session->userdata('user_group')==$this->config->item('user'))
			$this->db->where('rev',$user);
		elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
			$this->db->where('rev3',$user);		
						
		//All Data
		$this->db->where('status_id',$this->config->item('existing'));
		if(!$periode)
			$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',1);	
		elseif(($periode=='month') || ($periode=='3month') )
			$this->db->where('MONTH(date_stamp)',$month1);	
				
		$Q=$this->db->get('customers');
		$data=$Q->num_rows();
		/* Data  Month 1/ Week 1 */
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,$data);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+1,$row,$col+1,$row+1);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Cross Sealing');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        
		/* Result Week 1 / Month 1 */
		$this->db->where('pic',$user);
		$this->db->where('order_type','Repeat Order');
		if(!$periode)
			$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',1);		
		elseif(($periode=='month') || ($periode=='3month') )
			$this->db->where('MONTH(date_stamp)',$month1);
				
		$Q=$this->db->get('jobs');
		$data=$Q->num_rows();
		/* Result Week 1 / Month 1 */	
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$data);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
       
		
		if($periode != 'month'):
			/* Data  Week 2 / Month 2 */
			//WEEK ke 2
			if($this->session->userdata('user_group')==$this->config->item('user'))
				$this->db->where('rev',$user);
			elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
				$this->db->where('rev3',$user);		
							
			//All Data
			$this->db->where('status_id',$this->config->item('existing'));
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',2);	
			elseif(($periode=='3month') )
				$this->db->where('MONTH(date_stamp)',$month2);
					
			$Q=$this->db->get('customers');
			$data=$Q->num_rows();
			/* Data  Month 1/ Week 1 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+4,$row,$col+4,$row+1);
		   
			/* Result Week 2 / Month 2 */
			$this->db->where('pic',$user);
			$this->db->where('order_type','Repeat Order');
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',2);
			elseif(($periode=='3month') )
				$this->db->where('MONTH(date_stamp)',$month2);
					
			$Q=$this->db->get('jobs');
			$data=$Q->num_rows();
			/* Result Week 2 / Month 2 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			
			
			/* Data  Week 3 / Month 3 */
			//WEEK ke 3
			if($this->session->userdata('user_group')==$this->config->item('user'))
				$this->db->where('rev',$user);
			elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
				$this->db->where('rev3',$user);		
							
			//All Data
			$this->db->where('status_id',$this->config->item('existing'));
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',3);	
			elseif(($periode=='3month') )
				$this->db->where('MONTH(date_stamp)',$month3);
					
			$Q=$this->db->get('customers');
			$data=$Q->num_rows();
			/* Data  Month 1/ Week 1 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
			$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+6,$row,$col+6,$row+1);
			
			
			/* Result Week 3 / Month 3 */
			$this->db->where('pic',$user);
			$this->db->where('order_type','Repeat Order');
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',3);
			elseif(($periode=='3month') )
				$this->db->where('MONTH(date_stamp)',$month3);
					
			$Q=$this->db->get('jobs');
			$data=$Q->num_rows();
			/* Result Week 3 / Month 3 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			
			if(!$periode):
				/* Data  Week 4 */
				//WEEK ke 4
				if($this->session->userdata('user_group')==$this->config->item('user'))
					$this->db->where('rev',$user);
				elseif($this->session->userdata('user_group')==$this->config->item('user_dna'))
					$this->db->where('rev3',$user);		
								
				//All Data
				$this->db->where('status_id',$this->config->item('existing'));
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',4);	
				$Q=$this->db->get('customers');
				$data=$Q->num_rows();
				/* Data  Week 4 */
			
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,$data);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
				$objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow($col+8,$row,$col+8,$row+1);
				
				/* Result Week 4 / Month 4 */
				$this->db->where('pic',$user);
				$this->db->where('order_type','Repeat Order');
				if(!$periode)
					$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',4);
				elseif(($periode=='3month') )
					$this->db->where('MONTH(date_stamp)',$month4);
						
				$Q=$this->db->get('jobs');
				$data=$Q->num_rows();
				/* Result Week 4 / Month 4 */
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,$data);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			endif;
		endif;
		
		//batas
		$row++;
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col,$row)->applyFromArray($styleArray);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+1,$row,'');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+1,$row)->applyFromArray($styleArray);
		
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+2,$row,'Repeat Order');
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+2,$row)->applyFromArray($styleArray);
        
		
		/* Result Week 1 / Month 1 */
		$this->db->where('pic',$user);
		$this->db->where('order_type','Repeat Order');
		if(!$periode)
			$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',1);
		elseif(($periode=='3month') || ($periode=='month') )
			$this->db->where('MONTH(date_stamp)',$month1);
					
		$Q=$this->db->get('jobs');
		$data=$Q->num_rows();
		/* Result Week 1 / Month 1 */
			
		$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+3,$row,$data);
		$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+3,$row)->applyFromArray($styleArray);
       
		
		
		if($periode != 'month'):
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+4,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+4,$row)->applyFromArray($styleArray);
		   
			
			/* Result Week 2 / Month 2 */
			$this->db->where('pic',$user);
			$this->db->where('order_type','Repeat Order');
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',2);
			elseif(($periode=='3month'))
				$this->db->where('MONTH(date_stamp)',$month2);
						
			$Q=$this->db->get('jobs');
			$data=$Q->num_rows();
			/* Result Week 2 / Month 2 */
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+5,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+5,$row)->applyFromArray($styleArray);
			
			
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+6,$row,'');
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+6,$row)->applyFromArray($styleArray);
			
			
			/* Result Week 3 / Month 3 */
			$this->db->where('pic',$user);
			$this->db->where('order_type','Repeat Order');
			if(!$periode)
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',3);
			elseif(($periode=='3month'))
				$this->db->where('MONTH(date_stamp)',$month3);
						
			$Q=$this->db->get('jobs');
			$data=$Q->num_rows();
			/* Result Week 3 / Month 3 */
			
			$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+7,$row,$data);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+7,$row)->applyFromArray($styleArray);
			
			if(!$periode):
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+8,$row,'');
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+8,$row)->applyFromArray($styleArray);
				
				/* Result Week 4 */
				$this->db->where('pic',$user);
				$this->db->where('order_type','Repeat Order');
				$this->db->where('(WEEK(date_stamp, 5) - WEEK(DATE_SUB(date_stamp, INTERVAL DAYOFMONTH(date_stamp) - 1 DAY), 5) + 0)=',4);
				$Q=$this->db->get('jobs');
				$data=$Q->num_rows();
				/* Result Week 4 */
				$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col+9,$row,$data);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
				$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($col+9,$row)->applyFromArray($styleArray);
			endif;
		endif;
		
		// Save it as an excel 2003 file
        $objWriter = IOFactory::createWriter($objPHPExcel, "Excel5");
        $file="Performance_".$user.".xls";
        $objWriter->save('crm-assets/'.$file);
        redirect('crm-assets/'.$file,301);
	}
	
}
